package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Setter
@Getter
public class Travel extends BaseDomain {

    public static final int STATE_REJECT = 0;//发布拒绝
    public static final int STATE_NORMAL = 1;//草稿
    public static final int STATE_WART = 2;//审核
    public static final int STATE_RELEASE = 3;//发布成功

    private String title;//标题
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;//旅游时间

    private String perExpends;//人均消费

    private Integer days;//旅游天数

    private Integer person;//跟谁去玩

    private User author;//作者
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;//创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;//发布时间

    private Boolean isPublic = true;//是否公开

    private Region place;//旅游地点

    private String coverUrl;//游记封面
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date lastUpdateTime;//最后更新时间

    private Integer state;//状态

    private TravelContent content;//游记内容

    private List<User> userBy;//点赞的对象

    private Integer viewCount=0;//游记的浏览数

    public String getStateName() {
        if (state != null) {
            if (state == STATE_REJECT) {
                return "发布拒绝";
            } else if (state == STATE_NORMAL) {
                return "草稿";
            } else if (state == STATE_WART) {
                return "待审核";
            }
            return "已发布";

        }else{
            return "";
        }
    }


    public String getJsonString(){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }

}